Unsupervised vs Supervised Learning:
Most of our focus has been on supervised learning methods such as regression and classification
In that setting we observe both a set of features \(X_1, X_2, ..., X_p\) for each object, as well as a response or outcome variable \(Y\). The goal is then to predict Y using \(X_1, X_2, ..., X_p\)
Here we instead focus on unsupervised learning, we where observe only the features \(X_1, X_2, ..., X_p\). We are not interested in prediction, because we do not have an associated response variable Y
The goal is to discover interesting things about the measurements: is there an informative way to visualize the data? Can we discover subgroups among the variables or among the observations?
We discuss two methods:
Principal components analysis, a tool used for data visualization or data pre-processing before supervised techniques are applied
Clustering, a broad class of methods for discovering unknown subgroups in data
Unsupervised learning is more subjective than supervised learning, as there is no simple goal for the analysis, such as prediction of a response
But techniques for unsupervised learning are of growing importance in a number of fields:
Subgroups of breast cancer patients grouped by their gene expression measurements
Groups of shoppers characterized by their browsing and purchase histories
Movies grouped by the ratings assigned by movie viewers
It is often easier to obtain unlabeled data — from a lab instrument or a computer — than labeled data, which can require human intervention
For example it is difficult to automatically assess the overall sentiment of a movie review: is it favorable or not?
PCA produces a low-dimensional representation of a dataset. It finds a sequence of linear combinations of the variables that have maximal variance, and are mutually uncorrelated
Apart from producing derived variables for use in supervised learning problems, PCA also serves as a tool for data visualization
The first principal component of a set of features \(X_1, X_2, ..., X_p\) is the normalized linear combination of the features
\(Z_1 = \phi_{11}X_1 + \phi_{21}X_2 + ... + \phi_{p1}X_p\)
We refer to the elements \(\phi_{11}, ..., \phi_{p1}\) as the loadings of the first principal component; together, the loadings make up the principal component loading vector \(\phi_1 = (\phi_{11} \phi_{21} ... \phi_{p1})^T\)
We constrain the loadings so that their sum of squares is equal to one, since otherwise setting these elements to be arbitrarily large in absolute value could result in an arbitrarily large variance
Example
Suppose we have a \(n×p\) data set \(X\). Since we are only interested in variance, we assume that each of the variables in \(X\) has been centered to have mean zero (that is, the column means of \(X\) are zero)
We then look for the linear combination of the sample feature values of the form
\(z_{i1} = \phi_{11}x_{i1} + \phi_{21}x_{i2} + ... + \phi_{p1}x_{ip}\)
Since each of the \(x_{ij}\) has mean zero, then so does \(z_{i1}\) (for any values of \(\phi_{j1}\)). Hench the sample variance of the \(z_{i1}\) can be written as \(\frac{1}{n} \sum_{i=1}^{n}z_{i1}^2\)
Plugging in (1) the first principal component loading vector solves the optimization problem
\(\underset{\phi_{11},...,\phi_{p1}}{maximize} \frac{1}{n} \sum_{i=1}^{n} (\sum_{j=1}^{p} \phi_{j1}x_{ij})^2\)
This problem can be solved via a singular-value decomposition of the matrix \(X\), a standard technique in linear algebra
We refer to \(Z_1\) as the first principal component, with realized values \(z_{11},...,z_{n1}\)
The loading vector φ1 with elements \(\phi_{11}, \phi_{21},...,\phi_{p1}\) defines a direction in feature space along which the data vary the most
If we project the n data points \(x_1,...,x_n\) onto this direction, the projected values are the principal component scores \(z_{11},...,z_{n1}\) themselves
The second principal component is the linear combination of \(X_1,...,X_p\) that has maximal variance among all linear combinations that are uncorrelated with \(Z_1\)
The second principal component scores \(z_{12},z{22},...,z_{n2}\) take the form
\(z_{i2} = \phi_{12}x_{i1} + \phi_{22}x_{i2} + ... + \phi_{p2}x_{ip}\)
It turns out that constraining \(Z_2\) to be uncorrelated with \(Z_1\) is equivalent to constraining the direction \(\phi_2\) to be orthogonal (perpendicular) to the direction \(\phi_1\). And so on
The principal component directions \(\phi_1, \phi_2, \phi_3, . . .\) are the ordered sequence of right singular vectors of the matrix \(\mathbf{X}\), and the variances of the components are \(\frac{1}{n}\) times the squares of the singular values. There are at most \(min(n − 1, p)\) principal components
Illustration
USAarrests data: For each of the fifty states in the United States, the data set contains the number of arrests per 100, 000 residents for each of three crimes: Assault, Murder, and Rape. We also record UrbanPop (the percent of the population in each state living in urban areas)
The principal component score vectors have length n = 50, and the principal component loading vectors have length p = 4
PCA was performed after standardizing each variable to have mean zero and standard deviation one
The first two principal components for the USArrests data
The blue state names represent the scores for the first two principal components
The orange arrows indicate the first two principal component loading vectors (with axes on the top and right). For example, the loading for Rape on the first component is 0.54, and its loading on the second principal component 0.17 [the word Rape is centered at the point (0.54, 0.17)]
This figure is known as a biplot, because it displays both the principal component scores and the principal component loadings
PCA loadings
PCA finds the hyperplane closest to the observations
The first principal component loading vector has a very special property: it defines the line in p-dimensional space that is closest to the n observations (using average squared Euclidean distance as a measure of closeness)
The notion of principal components as the dimensions that are closest to the n observations extends beyond just the first principal component
For instance, the first two principal components of a data set span the plane that is closest to the n observations, in terms of average squared Euclidean distance
If the variables are in different units, scaling each to have standard deviation equal to one is recommended
If they are in the same units, you might or might not scale the variables
To understand the strength of each component, we are interested in knowing the proportion of variance explained (PVE) by each one
The total variance present in a data set (assuming that the variables have been centered to have mean zero) is defined as
\(\sum_{j=1}^{p} Var(X_j) = \sum_{j=1}^{p} \frac{1}{n} \sum_{i=1}^{n} x_{ij}^2\)
It can be shown that \(\sum_{j=1}^{p} Var(X_j) = \sum_{m=1}^{M} Var(Z_m)\) with \(M=min(n-1,p)\)
Therefore, the PVE of the \(m_{th}\) principal component is given by the positive quantity between 0 and 1
The PVEs sum to one. We sometimes display the cumulative PVEs
If we use principal components as a summary of our data, how many components are sufficient?
The “scree plot” above can be used as a guide: we look for an “elbow”
Clustering refers to a very broad set of techniques for finding subgroups, or clusters, in a data set
We seek a partition of the data into distinct groups so that the observations within each group are quite similar to each other
It make this concrete, we must define what it means for two or more observations to be similar or different
Indeed, this is often a domain-specific consideration that must be made based on knowledge of the data being studied
PCA looks for a low-dimensional representation of the observations that explains a good fraction of the variance
Clustering looks for homogeneous subgroups among the observations
Suppose we have access to a large number of measurements (e.g. median household income, occupation, distance from nearest urban area, and so forth) for a large number of people
Our goal is to perform market segmentation by identifying subgroups of people who might be more receptive to a particular form of advertising, or more likely to purchase a particular product
The task of performing market segmentation amounts to clustering the people in the data set
In K-means clustering, we seek to partition the observations into a pre-specified number of clusters
In hierarchical clustering, we do not know in advance how many clusters we want; in fact, we end up with a tree-like visual representation of the observations, called a dendrogram, that allows us to view at once the clusterings obtained for each possible number of clusters, from 1 to n
K-means clustering
A simulated data set with 150 observations in 2-dimensional space. Panels show the results of applying K-means clustering with different values of K, the number of clusters. The color of each observation indicates the cluster to which it was assigned using the K-means clustering algorithm. Note that there is no ordering of the clusters, so the cluster coloring is arbitrary. These cluster labels were not used in clustering; instead, they are the outputs of the clustering procedure
Details of K-means Clustering
Let \(C_1, ..., C_K\) denote sets containing the indices of the observations in each cluster. These sets satisfy two properties:
\(C_1 \cup C_2 \cup ... \cup C_K = \left\{1,...,n \right\}\) In other words,each observation belongs to at least one of the K clusters
\(C_k \cap C_{k'} = \emptyset\) for all \(k\neq k'\). In other words, the clusters are non-overlapping: no observation belongs to more than one cluster
For instance, if the \(i_th\) observation is in the \(k_th\) cluster, then \(i \in C_k\)
The idea behind K-means clustering is that a good clustering is one for which the within-cluster variation is as small as possible
The within-cluster variation for cluster \(C_k\) is a measure \(WCV(C_k)\) of the amount by which the observations within a cluster differ from each other
Hence we want to solve the problem
In words, this formula says that we want to partition the observations into \(K\) clusters such that the total within-cluster variation, summed over all \(K\) clusters, is as small as possible
Randomly assign a number, from 1 to K, to each of the observations. These serve as initial cluster assignments for the observations
Iterate until the cluster assignments stop changing:
For each of the K clusters, compute the cluster centroid. The kth cluster centroid is the vector of the p feature means for the observations in the kth cluster
Assign each observation to the cluster whose centroid is closest (where closest is defined using Euclidean distance)
Properties f the Algorithm
This algorithm is guaranteed to decrease the value of the objective at each step
However it is not guaranteed to give the global minimum
Example
The progress of the K-means algorithm with K=3
Top left: The observations are shown
Top center: In Step 1 of the algorithm, each observation is randomly assigned to a cluster
Top right: In Step 2(a), the cluster centroids are computed. These are shown as large colored disks. Initially the centroids are almost completely overlapping because the initial cluster assignments were chosen at random
Bottom left: In Step 2(b), each observation is assigned to the nearest centroid
Bottom center: Step 2(a) is once again performed, leading to new cluster centroids
Bottom right: The results obtained after 10 iterations
Example with different starting values
K-means clustering performed six times on the data from previous figure with K = 3, each time with a different random assignment of the observations in Step 1 of the K-means algorithm
Above each plot is the value of the objective. Three different local optima were obtained, one of which resulted in a smaller value of the objective and provides better separation between the clusters
Those labeled in red all achieved the same best solution, with an objective value of 235.8
K-means clustering requires us to pre-specify the number of clusters K. This can be a disadvantage (later we discuss strategies for choosing K)
Hierarchical clustering is an alternative approach which does not require that we commit to a particular choice of K
In this section, we describe bottom-up or agglomerative clustering. This is the most common type of hierarchical clustering, and refers to the fact that a dendrogram is built starting from the leaves and combining clusters up to the trunk
Builds a hierarchy in a “bottom-up” fashion:
The approach in words:
Start with each point in its own cluster
Identify the closest two clusters and merge them
Repeat
Ends when all points are in a single cluster
Left: Dendrogram obtained from hierarchically clustering the data from previous slide, with complete linkage and Euclidean distance
Center: The dendrogram from the left-hand panel, cut at a height of 9 (indicated by the dashed line). This cut results in two distinct clusters, shown in different colors
Right: The dendrogram from the left-hand panel, now cut at a height of 5. This cut results in three distinct clusters, shown in different colors. Note that the colors were not used in clustering, but are simply used for display purposes in this figure
So far have used Euclidean distance
An alternative is correlation-based distance which considers two observations to be similar if their features are highly correlated
This is an unusual use of correlation, which is normally computed between variables; here it is computed between the observation profiles for each pair of observations
Scaling of the variables matters!. Should the observations or features first be standardized in some way? For instance, maybe the variables should be centered to have mean zero and scaled to have standard deviation one
In the case of hierarchical clustering
What dissimilarity measure should be used?
What type of linkage should be used?
How many clusters to choose? (in both K-means or hierarchical clustering). Difficult problem. No agreed-upon method
Which features should we use to drive the clustering?
Unsupervised learning is important for understanding the variation and grouping structure of a set of unlabeled data, and can be a useful pre-processor for supervised learning
It is intrinsically more difficult than supervised learning because there is no gold standard (like an outcome variable) and no single objective (like test set accuracy)
It is an active field of research, with many recently developed tools such as self-organizing maps, independent components analysis and spectral clustering